home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1563 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: gate.net!pslfl2-38
  2. From: bhutto@gate.net (William Hutto)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help:  crash when doing fprintf
  5. Date: 15 Jan 1996 10:13:20 GMT
  6. Organization: CyberGate, Inc.
  7. Message-ID: <4dd9c0$11lo@news.gate.net>
  8. References: <DL74rA.L5v@info.physics.utoronto.ca>
  9. NNTP-Posting-Host: pslfl2-38.gate.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <DL74rA.L5v@info.physics.utoronto.ca>,
  13.    olivers@helios.physics.utoronto.ca (Oliver Schonborn) wrote:
  14. >
  15. >Hello folks!
  16. >
  17. >My program crashes when it executes the following statements:
  18. >
  19. >        char frootn[200]=".",
  20. >         fout[200]  ="";
  21. >        float time;
  22. >        FILE *fp;
  23.  
  24. How much stack do you have allocated? Have you tried defining some of your 
  25. locals (especially large ones) static? 
  26.  
  27.  
  28. >        ....
  29. >    sprintf(fout,"%s/test%-.5g",frootn,time);
  30. >    printf("Outputting to %s...\n",fout);
  31. >    fp=fopen(fout,"w");
  32.  
  33. I have to figure you've tested this in a debugger and know that fp != NULL, 
  34. but do you know the internal representation of NULL on your machine? No reason 
  35. not to test this FILE * in your code.
  36.  
  37. >    fprintf(fp,"Hello\n");
  38. >
  39. >This is what fp points to at crash time:
  40. >
  41. >0x40001038  struct FILE {
  42. >    __cnt = 0;
  43. >    __ptr =   00000000;
  44. >    __base =   00000000;
  45. >    __flag = 2;
  46. >    __fileL = 3;
  47. >    __fileH = 0;
  48. >}
  49. >
  50. >It crashes deep inside the fprintf.  A trace with the debugger
  51. >indicates where (main called _fprintf which called _wrtchk which
  52. >called _findbuf which called malloc):
  53. >
  54. > 0 malloc@libc + 0x00000470 (0x7b012538, 0x7b011168, 0x7b011164, 0x7b011160)
  55. > 1 _findbuf@libc + 0x000000fc (0x160, 0x8, 0x160, 0x7b0335b0)
  56. > 2 _wrtchk@libc + 0x00000058 (0x40061f40, 0x40061d38, 0x40061938, 0x3f7b53d2)
  57. > 3 _fprintf@libc + 0x00000024 (0x3c23d71a, 0x7b0336e4, 0x7b014e60, 
  58. 0x7b014e6c)
  59. > 4 main (argc = 3, argv = 0x7b033494)    [sfbynorm.c: 556]
  60. >
  61. >I've never seen anything like that bug before.  I used gcc 2.7.1
  62. >with -Wall -pedantic and get no warnings whatsoever.  With lint the
  63. >only warning I get is a possible pointer alignment problem from the
  64. >2 lines which define (and initialize) frootn[] and fout[], though I
  65. >don't know whether I should take that seriously.
  66. >
  67. >Anybody have any clue?  Thanks for any help,
  68. >
  69. >Oliver
  70.  
  71.  
  72. Bill
  73.  
  74. "Whatcha got on?...Your mind?"
  75.